home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-27 | 7.0 KB | 262 lines | [TEXT/CWIE] |
- // ===========================================================================
- // PP Basic Starter.cp ©1994-1997 Metrowerks Inc. All rights reserved.
- // ===========================================================================
- //
- // This file contains the starter code for a basic PowerPlant application
-
- #include "PP Basic Starter.h"
-
- #include <LGrowZone.h>
- #include <LWindow.h>
- #include <PP_Messages.h>
- #include <PP_Resources.h>
- #include <PPobClasses.h>
- #include <UDrawingState.h>
- #include <UMemoryMgr.h>
- #include <URegistrar.h>
- #include <LEditField.h>
- #include "beeper.h"
- #include "speech.proto.h"
- #include "OTdsp.h"
-
- Boolean gCanSpeak;
- short gSelectedVoiceIndex;
- short gNumberVoices;
- short gSpeakingVoiceIndex;
- Boolean gSpeakSelectionEnabled;
- SpeechChannel gSpeechChannel;
- OSErr gSpeechErrors[];
- Handle gSpeechText;
- VoiceSpec ** gVoices;
- long gConnID;
-
- // put declarations for resource ids (ResIDTs) here
-
- const ResIDT window_Sample = 1; // EXAMPLE
-
- BeeperGlobals *gInitGlobals;
-
- // ===========================================================================
- // • Main Program
- // ===========================================================================
-
- void main(void)
- {
- // Set Debugging options
- SetDebugThrow_(debugAction_Alert);
- SetDebugSignal_(debugAction_Alert);
-
- InitializeHeap(3); // Initialize Memory Manager
- // Parameter is number of Master Pointer
- // blocks to allocate
-
- // Initialize standard Toolbox managers
- UQDGlobals::InitializeToolbox(&qd);
-
- new LGrowZone(20000); // Install a GrowZone function to catch
- // low memory situations.
-
- Str31 Server = "\pTalker";
- gConnID = OTdspListen(Server);
- CPPStarterApp theApp; // replace this with your App type
- theApp.Run();
- StopSpeaking(); //kill current speech if any
- OTClose(gConnID);
- }
-
-
- // ---------------------------------------------------------------------------
- // • CPPStarterApp // replace this with your App type
- // ---------------------------------------------------------------------------
- // Constructor
-
- CPPStarterApp::CPPStarterApp()
- {
- // Register functions to create core PowerPlant classes
-
- RegisterAllPPClasses();
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~CPPStarterApp // replace this with your App type
- // ---------------------------------------------------------------------------
- // Destructor
- //
-
- CPPStarterApp::~CPPStarterApp()
- {
- }
-
- // ---------------------------------------------------------------------------
- // • StartUp
- // ---------------------------------------------------------------------------
- // This function lets you do something when the application starts up
- // without a document. For example, you could issue your own new command.
-
- void
- CPPStarterApp::StartUp()
- {
- // ObeyCommand(cmd_New, nil); // EXAMPLE, create a new window
- long err;
- // SelectorFunctionUPP ourGestaltUPP;
- // long versionCheck;
- VoiceDescription defaultVoiceInfo;
- // err = Gestalt(kDTS_Signature, (long *)&ourGestaltUPP);
- // if (err == noErr) {
- // err = CallSelectorFunctionProc(ourGestaltUPP, gestaltVersion, (long *)&versionCheck);
- // if (versionCheck != 0x0100) err = -1;
- // if (err == noErr) {
- // err = CallSelectorFunctionProc(ourGestaltUPP, kGestaltGetInitGlobals, (long *)&gInitGlobals);
- gCanSpeak = !gCanSpeak;
- //get default voice
- err = GetVoiceDescription(nil, &defaultVoiceInfo, sizeof(defaultVoiceInfo));
- err = NewSpeechChannel(&defaultVoiceInfo.voice, &gSpeechChannel);
- // }
- // }
- }
-
- // ---------------------------------------------------------------------------
- // • ObeyCommand
- // ---------------------------------------------------------------------------
- // Respond to commands
-
- Boolean
- CPPStarterApp::ObeyCommand(
- CommandT inCommand,
- void *ioParam)
- {
- Boolean cmdHandled = true;
-
- switch (inCommand) {
-
- // Deal with command messages (defined in PP_Messages.h).
- // Any that you don't handle will be passed to LApplication
-
- case cmd_New:
- // EXAMPLE, create a new window
- LWindow *theWindow;
- theWindow = LWindow::CreateWindow(window_Sample, this);
- theWindow->Show();
- break;
-
-
-
- default:
- cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- // ---------------------------------------------------------------------------
- // This function enables menu commands.
- //
-
- void
- CPPStarterApp::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
-
- switch (inCommand) {
-
- // Return menu item status according to command messages.
- // Any that you don't handle will be passed to LApplication
-
- case cmd_New: // EXAMPLE
- outEnabled = true; // enable the New command
- break;
-
- default:
- LApplication::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
-
-
- // ---------------------------------------------------------------------------
- // • ProcessNextEvent
- // ____________________________________________________________________________
- //
- void
- CPPStarterApp::ProcessNextEvent()
- {
- long status;
- Str31 word = "";
- // if(( gInitGlobals->lWriteBuf > gInitGlobals->lReadBuf ) ||
- // (( gInitGlobals->lWriteBuf == 0 ) && ( gInitGlobals->lReadBuf > 1 )))
- // {
- // Speak( gInitGlobals->asBuf[gInitGlobals->lReadBuf]);
- // gInitGlobals->asBuf[gInitGlobals->lReadBuf][0] = 0;
- // gInitGlobals->lReadBuf++;
- // if( gInitGlobals->lReadBuf > 4) gInitGlobals->lReadBuf = 0;
- // }
- if (gConnID > 0) status = OTdspStatus(gConnID);
- if(status == 10)
- {
- OTRecvText( gConnID, word);
- Speak( word );
- }
- LApplication::ProcessNextEvent();
- }
-
- // ----------------------------------------------------------------------------
- // • Speak
- // ----------------------------------------------------------------------------
-
- void
- CPPStarterApp::Speak(Str31 word)
- {
- OSErr err;
- // VoiceDescription defaultVoiceInfo;
-
-
- // StopSpeaking(); //kill current speech if any
-
- //get default voice
- // err = GetVoiceDescription(nil, &defaultVoiceInfo, sizeof(defaultVoiceInfo));
- // if (noErr != err) {
- // err = MakeVoiceSpec('\0\0\0\0', '\0\0\0\0', &defaultVoiceInfo.voice);
- // }
- /* Get a speech channel */
-
- // gSpeakingVoiceIndex = gSelectedVoiceIndex;
- // MoveHHi((Handle)gVoices);
- // HLock((Handle)gVoices);
- // err = NewSpeechChannel(&defaultVoiceInfo.voice, &gSpeechChannel);
- // HUnlock((Handle)gVoices);
- // if (noErr != err) {
-
- /* The voice that the user selected doesn't work; let's try the rest */
-
- // HLock((Handle)gVoices);
- // for (gSpeakingVoiceIndex = 0; gSpeakingVoiceIndex < gNumberVoices; gSpeakingVoiceIndex++) {
- // err = NewSpeechChannel(&(*gVoices)[gSpeakingVoiceIndex], &gSpeechChannel);
- // if (noErr == err) {
- // break;
- // }
- // }
- // HUnlock((Handle)gVoices);
- // if (gSpeakingVoiceIndex == gNumberVoices) {
- // StopSpeaking();
- // break;
- // }
- // }
-
- /* Start speaking the new text */
-
- err = SpeakText(gSpeechChannel, (char *)&word[1], word[0]);
- if (noErr != err) {
- StopSpeaking();
- }
-
- }
-